package org.ucas.faker.web.controller.visualization;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ucas.faker.web.controller.BaseController;
import org.ucas.faker.web.dto.CarryDto;
import org.ucas.faker.web.fetcher.FetchReqBuilder;
import org.ucas.faker.web.service.fishbone.FishboneSimpleService;
import org.ucas.faker.web.service.Visualization.DataService;
import org.ucas.faker.web.service.Visualization.LabelService;
import org.ucas.faker.web.service.Visualization.entity.VisualParam;
import org.ucas.faker.web.service.Visualization.json.JsonUtil;
import org.ucas.faker.web.service.heatmap.HeatmapByTreeService;

import java.io.IOException;
import java.util.List;

@RestController
@ResponseBody
public class LabelController extends BaseController{

    @Autowired
    private LabelService labelService;
    @Autowired
    private DataService dataService;
    @Autowired
    private FishboneSimpleService fishboneSimpleService;
    @Autowired
    private HeatmapByTreeService heatmapByTreeService;

    @RequestMapping(value = "/graph/draw/basis", method = RequestMethod.POST)
    @ResponseBody
    public CarryDto<String> labelRequest(@RequestParam(value = "graph_message", required = true) String json_string){

        long depotId = currentDepotId();

        JSONObject inputJson = JSONObject.parseObject(json_string);
        VisualParam param = new VisualParam();
        param.setDepotId(depotId);
        param.setBasisDimension(2);

        FetchReqBuilder requestBuilder = FetchReqBuilder.instance().depot(depotId);

        dataService.parseConstraint(inputJson, requestBuilder);
        dataService.parseData1D1T(inputJson, requestBuilder, param);
        List<String> resultList = JsonUtil.jsonArrayToList(param.getBasisLabel());

        return CarryDto.of(resultList);
    }

    @RequestMapping(value = "/graph/draw/xxx")
    @ResponseBody
    public String labelRequest() throws IOException {
        long depotId = 28;
        long treeId = 1;
        fishboneSimpleService.testSimple(depotId, treeId);
//        heatmapByTreeService.getHeatmap(depotId);
        return "success";
    }


}
